<template>
    <el-dialog title="编辑" :visible.sync="dialogFormVisible" :close-on-click-modal=this.$store.state.theme.interface.other.closeOnClickModal width="35%">
        <el-form ref="form" :model="form" :rules="rules" label-width="80px" size="small">
            <el-form-item label="标签名称" prop="name">
                <el-input v-model="form.name"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button size="mini" @click="dialogFormVisible = false">取 消</el-button>
            <el-button size="mini" type="primary" @click="edit()">确 定</el-button>
        </div>
    </el-dialog>
</template>
  
<script>
import { edit } from '@/api/user/label';
export default {
    name: "edit",
    data() {
        return {
            form: {
                name: ''
            },
            rules: {
                name: [
                    { required: true, message: '请输入标签名称', trigger: 'blur' }
                ]
            },
            dialogFormVisible: false
        }
    },
    mounted() {
    },
    watch: {
        rowData(val) {
            this.form = val;
        }
    },
    methods: {
        initData(row) {
            this.$nextTick(() => {
                this.form = JSON.parse(JSON.stringify(row))
            });
        },
        edit() {
            this.$refs['form'].validate((valid) => {
                if (valid) {
                    edit(this.form).then(res => {
                        this.dialogFormVisible = !this.dialogFormVisible;
                        this.$message({
                            message: res.msg,
                            type: 'success'
                        });
                        this.$emit('updateList');
                    })
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        }
    }
}
</script>
  
<style lang="less" scoped></style>